package br.ufcg.edu.routers;

import junit.framework.TestCase;
import br.ufcg.edu.routers.util.LinkMap;

public class RouterPacketManagerTest extends TestCase {
	
	public void testCreateLinkMap() {
		RouterPacketManager manager = new RouterPacketManager();
		
		LinkMap linkMap = manager.createLinkMap("1,2#3,4#5,6#".getBytes());
		assertEquals("{1=2, 3=4, 5=6}", linkMap.toString());
		linkMap = manager.createLinkMap("1,2#".getBytes());
		assertEquals("{1=2}", linkMap.toString());
		linkMap = manager.createLinkMap("      1,2#      ".getBytes());
		assertEquals("{1=2}", linkMap.toString());
		
	}
	
	public void testCreatePacketToSend() {
		RouterPacketManager manager = new RouterPacketManager();
		
		LinkMap linkMap = new LinkMap();
		linkMap.put(1, 3);
		linkMap.put(4, 5);
		linkMap.put(2, 3);
		
		assertEquals("1,3#2,3#4,5#", new String(manager.createPacketToSend(1, linkMap)));
		
		linkMap = new LinkMap();
		linkMap.put(1, 3);
		linkMap.put(4, 1);

		assertEquals("1,3#4,1#", new String(manager.createPacketToSend(2, linkMap)));
		
		linkMap.put(4, 2, 1);
		
		assertEquals("1,3#4," + Router.INFINITY + "#", new String(manager.createPacketToSend(2, linkMap)));
		
		linkMap = new LinkMap();
		linkMap.put(1, 1);
		
		assertEquals("1,1#", new String(manager.createPacketToSend(3, linkMap)));
		
	}

}
